package view;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;

public class ChessButton implements ActionListener {
	private int x,y;
	private Color defaultColor;
	private JButton button;
	private ArrayList<ActionListener> listenerList;
	
	public ChessButton(int x,int y, Color color){
		this.x=x;
		this.y=y;
		defaultColor=color;
		button = new JButton("");
		button.addActionListener(this);  //This will be to allow this class to send an
										//ActionEvent to the gui, with a reference to 
										//itself, allowing the gui access to more useful 
										//information
		
		listenerList=new ArrayList<ActionListener>(); //This is needed to allow the GUI (And
													  //anything else) to listen to the events
													  //generated by this button
	}
	
	public int getX(){
		return this.x;
	}
	
	public int getY(){
		return this.y;
	}
	
	public Color getColor(){
		return defaultColor;
	}
	
	public JButton getButton(){
		return this.button;
	}

	public void addActionListener(ActionListener act){
		listenerList.add(act);
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		ActionEvent a = new ActionEvent(this,ActionEvent.ACTION_PERFORMED,arg0.getActionCommand(),arg0.getWhen(),arg0.getModifiers());
		for (ActionListener act: listenerList){
			act.actionPerformed(a);  //Notify all listeners of the event generated by the button
		}
		
	}

	public void setColor(Color gridColour) {
		defaultColor=gridColour;
		
	}
}
